const {
  override,
  fixBabelImports,
  addWebpackAlias,
  addPostcssPlugins,
} = require('customize-cra')

const path = require('path')
const px2viewport = require('postcss-px-to-viewport')

// 样式按需加载配置
const babelconfigs = fixBabelImports('import', {
  libraryName: 'antd-mobile',
  style: 'css',
})

// 文件引入路径别名配置
const alias = addWebpackAlias({
  '@': path.resolve(__dirname, 'src'),
  '@scss': path.resolve(__dirname, 'src', 'assets', 'styles'),
})

// 配置postcss样式转换插件
const postcssPlugins = addPostcssPlugins([
  // 移动端适配
  px2viewport({
    viewportWidth: 375,
  }),
])

module.exports = override(babelconfigs, alias, postcssPlugins)
